package com.yunfeng.learning;

import io.swagger.annotations.Api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackages = "com.yunfeng.learning.controller")
public class SwaggerSpringBootApplication {

	public static void main(String[] args) {
	    SpringApplication.run(SwaggerSpringBootApplication.class, args);
	}

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo("Demo  API", "Simple REST Service", "0.0.1",
                "", new Contact("", "", ""), "", "");
        return apiInfo;
    }

    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .build()
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfo());
    }
}
